/**
 * 
 */
package org.jenkon.commons.lang.builder;

import org.jenkon.commons.lang.Resetable;
import org.jenkon.commons.lang.validator.Validator;

/**
 * @author Jens Konopka
 * 
 */
public class ValidatorBuilder implements Resetable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6733229470215667615L;

	private boolean valid = true;

	/**
	 * @param validator
	 * @param value
	 * @throws Exception
	 */
	public <T> void append(final Validator<T> validator, final T value)
			throws Exception {
		append(validator, value, false);
	}

	/**
	 * @param validator
	 * @param value
	 * @param exclude
	 * @throws Exception
	 */
	public <T> void append(final Validator<T> validator, final T value,
			final boolean exclude) throws Exception {

		if (valid) {

			if (!exclude) {

				if (!validator.validate(value)) {
					valid = false;
				}

			}

		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jenkon.commons.Resetable#reset()
	 */
	@Override
	public void reset() {
		valid = true;
	}

	/**
	 * @return the valid
	 */
	public boolean isValid() {
		return valid;
	}

}
